# !/python/TextResuming/util/preprocess.py
# stemming

from stemming.porter2 import stem
import nltk
import unicodedata
import string

def stemListOfSentence(listOfSentence):
    '''Stem a list of sentence using stemming module.

        Return a list of stemmed sentence.'''
    listOfStemmedSentence = []
    for sentence in listOfSentence:
        listOfStemmedSentence.append(stemSentence(sentence))
    return listOfStemmedSentence

def stemSentence(sentence):
    '''Stem a sentence using stemming module.

        Return a stemmed sentence.'''
    #listWord = sentence.split() #using split function
    listWord = nltk.word_tokenize(sentence) #using nltk
    listStemmedWord = []
    for word in listWord:
        listStemmedWord.append(stem(word))
    return ' '.join(listStemmedWord)

def normalizeString(stringAbsurd):
    '''Normalize a string from unicode character.'''
    return unicodedata.normalize('NFKD', stringAbsurd.decode('latin-1')).encode('ascii', 'ignore')

def removePunctuation(stringAbsurd):
    '''Removing punctuation from a string.'''
    for punct in string.punctuation:
        stringAbsurd = stringAbsurd.replace(punct, '')
    return stringAbsurd

def removeStopWord(listWord):
    '''Removing stop word from a list of word.'''
    stopWords = nltk.corpus.stopwords.words('english')
    for stopWord in stopWords:
        listWord.remove(stopWord)

    return listWord

def printAyuList(list):
    i = 1
    for elmt in list:
        print i, elmt
        i += 1

def main():
    a = "Seattle-based Aviation Partners (API), patent-holder of the blended winglet, is seeking the dismissal of an Airbus lawsuit aiming to clarify the intellectual property rights of the European airframer's alleged use of API's winglet on the Airbus A320's sharklets."
    b = "Air New Zealand currently serves as launch customer for the sharklets, and anticipates the delivery of its first A320 with winglets later this year."
    c = "The implications of the lawsuit filed by Airbus could nullify any royalty claims by API, if Airbus's sharklet design is found to use API's intellectual property."

    listOfSentence = [a,b,c]
    printAyuList(stemListOfSentence(listOfSentence))
    printAyuList(listOfSentence)

if __name__ == '__main__':
    main()
